/*
 * Copyright 2013 floreysoft GmbH (www.floreysoft.net)
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.floreysoft.gwt.drive.client.realtime;

/**
 * An IndexReference is a pointer to a specific location in a collaborative list
 * or string. This pointer automatically shifts as new elements are added to and
 * removed from the object.
 * 
 * To listen for changes to the referenced index, add an EventListener for
 * gapi.drive.realtime.EventType.REFERENCE_SHIFTED.
 * 
 * This class should not be instantiated directly. To create an index reference,
 * call registerReference on the appropriate string or list.
 * 
 */
public final class IndexReference extends CollaborativeObject {
	protected IndexReference() {

	}

	public native void setIndex(int index) /*-{
		this.index = index;
	}-*/;
 
	
	/**
	 * @return The index of the current location the reference points to. Write
	 *         to this property to change the referenced index.
	 */
	public native int index() /*-{
		return this.index;
	}-*/;

	/**
	 * @return Whether this reference can be deleted. Read-only. This property
	 *         affects the behavior of the index reference when the index the
	 *         reference points to is deleted. If this is true, the index
	 *         reference will be deleted. If it is false, the index reference
	 *         will move to point at the beginning of the deleted range.
	 */
	public native boolean canBeDeleted() /*-{
		return !!this.canBeDeleted;
	}-*/;

	/**
	 * @return The object this reference points to. Read-only.
	 */
	public native CollaborativeObject referencedObject() /*-{
		return this.referencedObject;
	}-*/;

}
